home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Telnet 2.6.1d1 4⁄26⁄94 Folder / source / config / Sets.c < prev    next >
Text File  |  1994-04-13  |  21KB  |  766 lines

  1. /*
  2. *    Sets.c
  3. *    All code relating to loading, parsing, and saving of sets
  4. *
  5. *****************************************************************
  6. *    NCSA Telnet for the Macintosh                                *
  7. *                                                                *
  8. *    National Center for Supercomputing Applications                *
  9. *    Software Development Group                                    *
  10. *    152 Computing Applications Building                            *
  11. *    605 E. Springfield Ave.                                        *
  12. *    Champaign, IL  61820                                        *
  13. *                                                                *
  14. *    Copyright (c) 1986-1993,                                    *
  15. *    Board of Trustees of the University of Illinois                *
  16. *****************************************************************
  17. *  Revisions:
  18. *  7/92        Telnet 2.6:    Code moved here from config.c and maclook.c...  Jim Browne
  19. */
  20.  
  21. #ifdef MPW
  22. #pragma segment Sets
  23. #endif
  24.  
  25. #include <stdio.h>            /* So sprintfs have protos... */
  26. #include <string.h>
  27. #include <ctype.h>
  28.  
  29. #include "TelnetHeader.h"
  30. #include "macros.proto.h"
  31. #include "wind.h"            /* For WindRec definition */
  32. #include "Sets.proto.h"
  33. #include "telneterrors.h"
  34. #include "prefs.proto.h"
  35. #include "debug.h"
  36. #include "Connections.proto.h"
  37. #include "rsmac.proto.h"
  38.  
  39. #include "vsdata.h"
  40. #include "vsinterf.proto.h"
  41.  
  42. //#define    DEBUG_SETS
  43. #ifdef    DEBUG_SETS
  44. #define    sets_debug_print(x) putln(x)
  45. #else
  46. #define sets_debug_print(x)
  47. #endif
  48.  
  49. ConnInitParams    **SetParams;
  50. SessionPrefs    *SetSessionPtr;
  51. TerminalPrefs    *SetTerminalPtr;
  52.  
  53. char            *Cspace;
  54.  
  55. extern WindRec
  56.     *screens;        /* Window Records (VS) for :    Current Sessions */
  57.  
  58. extern SysEnvRec theWorld;                        /* System Environment record */
  59.  
  60. extern MenuHandle
  61.     myMenus[NMENUS];        /* Menu Handles .... */
  62.  
  63. #define PORTNUM 37            /* NCSA 2.5: the port variable */
  64.  
  65. void    SETSunload(void)    {}
  66.  
  67. /* affirmative() checks a token to see if it is a valid Affirmation string.
  68.     We now get the affirmative strings from the resource */
  69.     
  70. Boolean    affirmative( char *s)
  71. {
  72.     short    i;
  73.     Str255    AffWords;        /* Telnet 2.6: get string resources */
  74.  
  75.     for (i=0; i<TelInfo->position; i++)
  76.         s[i] = tolower( s[i] );
  77.  
  78.     for (i=1; i<= AFF_WORDS_COUNT ;i++) 
  79.         {
  80.         GetIndString(AffWords,AFF_WORDS_ID,i);
  81.         p2cstr(AffWords);
  82.         if (!ncstrcmp((char *)AffWords,s))                
  83.         break;                                        
  84.         }
  85.         
  86.     if (i <= AFF_WORDS_COUNT)
  87.         return(TRUE);
  88.     else
  89.         return(FALSE);
  90. }
  91.  
  92. /**************************************************************************/
  93. /*  Sissep
  94. *   is the character a valid separator for the hosts file?
  95. *   separators are white space, special chars and :;=
  96. *
  97. */
  98. Boolean Sissep( char c)
  99. {
  100.     if (c < 33)
  101.         return(1);
  102.     if (c == ':' || c == ';' || c == '=')
  103.         return(TRUE);
  104.     return(FALSE);
  105. }
  106.  
  107. /************************************************************************/
  108. /*  ncstrcmp
  109. *   No case string compare.
  110. *   Only returns 0=match, 1=no match, does not compare greater or less
  111. *   There is a tiny bit of overlap with the | 32 trick, but shouldn't be
  112. *   a problem.  It causes some different symbols to match.
  113. */
  114. short ncstrcmp(char *sa, char *sb)
  115. {
  116.     while (*sa && *sa < 33)        /* don't compare leading spaces */
  117.         sa++;
  118.     while (*sb && *sb < 33)
  119.         sb++;
  120.  
  121.     while (*sa && *sb) {
  122.         if ((*sa != *sb) && ((*sa | 32) != (*sb | 32)))
  123.             return(1);
  124.         sa++;sb++;
  125.     }
  126.     if (!*sa && !*sb)        /* if both at end of string */
  127.         return(0);
  128.     else
  129.         return(1);
  130. }
  131.  
  132. /* confile() now gets all of its keywords from the string resources, for greater
  133.     ease, flexibility, and overall coolness.  */
  134. short confile( char *s)
  135. {
  136.     short        i, port;
  137.     Boolean        success;
  138.     unsigned    int a,b,c,d;
  139.     int            signedint;
  140.     Str255        Ckeyw;
  141.     char        tempCstring[256];
  142.     
  143.     sets_debug_print(s);
  144.     if (!(*s) )
  145.         return(0);
  146.  
  147.     switch( TelInfo->CONFstate) {
  148.         case 0:                /* No keyword yet! */
  149.             for (i=0; i<TelInfo->position; i++)
  150.                 s[i] = tolower( s[i] );
  151.  
  152.             for (i=1; i<= SAVE_SET_STRINGS_COUNT ;i++) 
  153.                 {
  154.                 GetIndString(Ckeyw,SAVE_SET_STRINGS_ID,i);
  155.                 p2cstr(Ckeyw);
  156.                 if (!ncstrcmp((char *)Ckeyw,s))                
  157.                 break;                                        
  158.                 }
  159.  
  160.             if ( i > SAVE_SET_STRINGS_COUNT ) 
  161.                 {
  162.                 OperationFailedAlert(BAD_SET_ERR, 0, 0);
  163.                 return(1);
  164.                 }
  165.  
  166.             TelInfo->CONFstate=i;
  167.  
  168.             if (TelInfo->CONFstate==5) {
  169.                 SetSessionPtr->bksp = 0;
  170.                 TelInfo->CONFstate=0;
  171.                 }
  172.             if (TelInfo->CONFstate==6) {
  173.                 SetSessionPtr->bksp = 1;
  174.                 TelInfo->CONFstate=0;
  175.                 }
  176.             break;
  177.  
  178.         case 1:                /* NAME */
  179.             { char *p;
  180.             if (NULL == (p = NewPtr(40000)))         /* is there enough memory? */
  181.                 {                    /* NOT enough memory for the set! */
  182.                 DoError(107 | MEMORY_ERRORCLASS, LEVEL2, NULL);    /* register the error */
  183.                 return(-1);
  184.                 }
  185.             else
  186.                 DisposPtr(p);
  187.             }
  188.             if (TelInfo->CONFactive) {
  189.                 success = CreateConnectionFromParams(SetParams);
  190.                 SetParams = NULL;
  191.                 if (!success) {
  192.                     sets_debug_print("ERROR IN OPENING!! ");
  193.                     return(42);
  194.                     }
  195.                 }
  196.  
  197.             if (SetParams == NULL) {
  198.                 SetParams = ReturnDefaultConnInitParams();
  199.                 HLockHi((Handle)SetParams);
  200.                 HLockHi((Handle)(**SetParams).session);
  201.                 SetSessionPtr = *(**SetParams).session;
  202.                 HLockHi((Handle)(**SetParams).terminal);
  203.                 SetTerminalPtr = *(**SetParams).terminal;
  204.                 }
  205.                 
  206.             strncpy(tempCstring, s, 255);            /* Move name in */
  207.             CtoPstr(tempCstring);
  208.             BlockMove(tempCstring, (**SetParams).WindowName, tempCstring[0]+1);
  209.             TelInfo->CONFstate=0;
  210.             TelInfo->CONFactive=1;
  211.             break;
  212.  
  213.         case 2:                /* HOST */
  214.             strncpy(tempCstring, s, 63);            /* Move name in */
  215.             CtoPstr(tempCstring);
  216.  
  217.             //    Process the hosname string.
  218.             if (ProcessHostnameString((StringPtr)tempCstring, &port))
  219.                 SetSessionPtr->port = port;
  220.             
  221.             BlockMove(tempCstring, SetSessionPtr->hostname, tempCstring[0]+1);
  222.  
  223.             TelInfo->CONFstate=0;
  224.             break;
  225.  
  226.         case 3:                /* SIZE */
  227.             if ( 4 != sscanf(s, "{%d,%d,%d,%d}", &a, &b, &c,&d) ) {
  228.                 sets_debug_print("Error in window size");
  229.                 return(2);
  230.                 }
  231.             
  232.             (**SetParams).WindowLocation.top=a;
  233.             (**SetParams).WindowLocation.left=b;
  234.             (**SetParams).WindowLocation.bottom=c;
  235.             (**SetParams).WindowLocation.right=d;
  236.             TelInfo->CONFstate=0;
  237.             break;
  238.  
  239.         case 4:
  240.             if ( 1 != sscanf(s,"%d", &a) ) {
  241.                 sets_debug_print("Scrollback needs parameter");
  242.                 return(1);
  243.                 }
  244.             SetTerminalPtr->numbkscroll = a;
  245.             TelInfo->CONFstate=0;
  246.             break;
  247.  
  248.         case 5:
  249.             SetSessionPtr->bksp = 0;            
  250.             TelInfo->CONFstate=0;
  251.             break;
  252.  
  253.         case 6:
  254.             SetSessionPtr->bksp = 1;
  255.             TelInfo->CONFstate=0;
  256.             break;
  257.  
  258.         case 7:
  259.             setmacro( 0, (unsigned char *) s);
  260.             TelInfo->CONFstate=0;
  261.             break;
  262.         case 8:
  263.             setmacro( 1, (unsigned char *) s);
  264.             TelInfo->CONFstate=0;
  265.             break;
  266.         case 9:
  267.             setmacro( 2, (unsigned char *) s);
  268.             TelInfo->CONFstate=0;
  269.             break;
  270.         case 10:
  271.             setmacro( 3, (unsigned char *) s);
  272.             TelInfo->CONFstate=0;
  273.             break;
  274.         case 11:
  275.             setmacro( 4, (unsigned char *) s);
  276.             TelInfo->CONFstate=0;
  277.             break;
  278.         case 12:
  279.             setmacro( 5, (unsigned char *) s);
  280.             TelInfo->CONFstate=0;
  281.             break;
  282.         case 13:
  283.             setmacro( 6, (unsigned char *) s);
  284.             TelInfo->CONFstate=0;
  285.             break;
  286.         case 14:
  287.             setmacro( 7, (unsigned char *) s);
  288.             TelInfo->CONFstate=0;
  289.             break;
  290.         case 15:
  291.             setmacro( 8, (unsigned char *) s);
  292.             TelInfo->CONFstate=0;
  293.             break;
  294.         case 16:
  295.             setmacro( 9, (unsigned char *) s);
  296.             TelInfo->CONFstate=0;
  297.             break;
  298.         case 17:
  299.             TelInfo->CONFstate=0;        // Now ignored (was commandkeys)
  300.             break;
  301.         case 18:
  302.             if (!strcmp(s,"backspace") )
  303.                 SetSessionPtr->bksp = 0;
  304.             else
  305.                 SetSessionPtr->bksp = 1;
  306.             TelInfo->CONFstate=0;
  307.             break;
  308.         case 19:
  309.         case 21:
  310.             if ( 1 == sscanf(s,"%d", &a) ) 
  311.                 SetTerminalPtr->vtwidth = a;
  312.             TelInfo->CONFstate=0;
  313.             break;
  314.         case 20:
  315.             if (affirmative(s))
  316.                 SetSessionPtr->tekclear = 1;
  317.             else
  318.                 SetSessionPtr->tekclear = 0;
  319.             TelInfo->CONFstate = 0;
  320.             break;
  321.         case 22:
  322.             if ( 3 != sscanf(s, "{%u,%u,%u}", &a, &b, &c)) {    /* BYU LSC - "%d" changed to "%u" */
  323.                 sets_debug_print("Bad Parms to rgb");
  324.                 return(2);
  325.                 }
  326.             SetTerminalPtr->nfcolor.red = a;
  327.             SetTerminalPtr->nfcolor.green = b;
  328.             SetTerminalPtr->nfcolor.blue = c;
  329.             TelInfo->CONFstate = 0;
  330.             break;            
  331.         case 23:
  332.             if ( 3 != sscanf(s, "{%u,%u,%u}", &a, &b, &c)) {    /* BYU LSC - "%d" changed to "%u" */
  333.                 sets_debug_print("Bad Parms to rgb");
  334.                 return(2);
  335.                 }
  336.             SetTerminalPtr->nbcolor.red = a;
  337.             SetTerminalPtr->nbcolor.green = b;
  338.             SetTerminalPtr->nbcolor.blue = c;
  339.             TelInfo->CONFstate = 0;
  340.             break;            
  341.         case 24:
  342.             if ( 3 != sscanf(s, "{%u,%u,%u}", &a, &b, &c)) {    /* BYU LSC - "%d" changed to "%u" */
  343.                 sets_debug_print("Bad Parms to rgb");
  344.                 return(2);
  345.                 }
  346.             SetTerminalPtr->bfcolor.red = a;
  347.             SetTerminalPtr->bfcolor.green = b;
  348.             SetTerminalPtr->bfcolor.blue = c;
  349.             TelInfo->CONFstate = 0;
  350.             break;            
  351.         case 25:
  352.             if ( 3 != sscanf(s, "{%u,%u,%u}", &a, &b, &c)) {    /* BYU LSC - "%d" changed to "%u" */
  353.                 sets_debug_print("Bad Parms to rgb");
  354.                 return(2);
  355.                 }
  356.             SetTerminalPtr->bbcolor.red = a;
  357.             SetTerminalPtr->bbcolor.green = b;
  358.             SetTerminalPtr->bbcolor.blue = c;
  359.             TelInfo->CONFstate = 0;
  360.             break;
  361.         case 26:        /* Font Name */
  362.             strncpy(tempCstring, s, 63);            /* Move name in */
  363.             CtoPstr(tempCstring);
  364.             BlockMove(tempCstring, &(SetTerminalPtr->DisplayFont[0]), tempCstring[0]+1);
  365.             TelInfo->CONFstate = 0;
  366.             break;
  367.         case 27:        /* Font Size */
  368.             if (1 == sscanf( s, "%d", &a))
  369.                 SetTerminalPtr->fontsize = a;
  370.             TelInfo->CONFstate = 0;
  371.             break;
  372.         case 28:        /* number of lines to use for window's editable region */
  373.             if (1 == sscanf( s, "%d", &a))
  374.                 SetTerminalPtr->vtheight = a;
  375.             TelInfo->CONFstate = 0;
  376.             break;
  377.         case 29:        /* keystop, XOFF key */
  378.             if (1 == sscanf( s, "%d", &a))
  379.                 SetSessionPtr->skey = a;
  380.             TelInfo->CONFstate = 0;
  381.             break;
  382.         case 30:        /* keygo, XON key */
  383.             if (1 == sscanf( s, "%d", &a))
  384.                 SetSessionPtr->qkey = a;
  385.             TelInfo->CONFstate = 0;
  386.             break;
  387.         case 31:        /* keyip, kill key */
  388.             if (1 == sscanf( s, "%d", &a))
  389.                 SetSessionPtr->ckey = a;
  390.             TelInfo->CONFstate = 0;
  391.             break;
  392.         case 32:        /* cr-map */
  393.             if ((1 == sscanf( s, "%d", &a)) && (a !=0))
  394.                 SetSessionPtr->crmap = TRUE;
  395.             else
  396.                 SetSessionPtr->crmap = FALSE;
  397.             TelInfo->CONFstate = 0;
  398.             break;
  399.         case 33:                    /* BYU 2.4.9 */
  400.             if (affirmative(s))        /* BYU 2.4.9 */
  401.                 SetSessionPtr->linemode = TRUE;    /* BYU 2.4.9 */
  402.             else                    /* BYU 2.4.9 */
  403.                 SetSessionPtr->linemode = FALSE;    /* BYU 2.4.9 */
  404.             TelInfo->CONFstate=0;            /* BYU 2.4.9 */
  405.             break;                    /* BYU 2.4.9 */
  406.         case 34:                    /* BYU 2.4.9 */
  407.             if (affirmative(s))        /* BYU 2.4.9 */
  408.                 SetTerminalPtr->eightbit = TRUE;    /* BYU 2.4.9 */
  409.             else                    /* BYU 2.4.9 */
  410.                 SetTerminalPtr->eightbit = FALSE;    /* BYU 2.4.9 */
  411.             TelInfo->CONFstate=0;            /* BYU 2.4.9 */
  412.             break;                    /* BYU 2.4.9 */
  413.         case 35:                    /* BYU */
  414.             (**SetParams).ftpstate = 1;        /* BYU */
  415.             TelInfo->CONFstate=0;            /* BYU */
  416.             break;                    /* BYU */
  417.         case 36:    // ignored
  418.             TelInfo->CONFstate=0;
  419.             break;
  420.         case PORTNUM:                            /* NCSA 2.5: get the real port # */
  421.             if (1 == sscanf( s, "%d", &a))        /* NCSA */
  422.                 SetSessionPtr->port = a;                /* NCSA */
  423.             TelInfo->CONFstate = 0;                /* NCSA */
  424.             break;                                /* NCSA */
  425.         case 38:    // translation
  426.             strncpy((char *) SetSessionPtr->TranslationTable, s, 32);
  427.             CtoPstr((char *) SetSessionPtr->TranslationTable);
  428.             TelInfo->CONFstate=0;
  429.             break;
  430.         case 39:    // tekem
  431.             if (1 == sscanf(s, "%d", &signedint))
  432.                 SetSessionPtr->tektype = signedint;
  433.             TelInfo->CONFstate=0;
  434.             break;
  435.         case 40:    // answerback
  436.             strncpy((char *) SetTerminalPtr->AnswerBackMessage, s, 32);
  437.             CtoPstr((char *) SetTerminalPtr->AnswerBackMessage);
  438.             TelInfo->CONFstate=0;
  439.             break;
  440.         default:
  441.             TelInfo->CONFstate=0;
  442.         }
  443.     return(0);
  444.   } /* confile */
  445.  
  446. /************************************************************************/
  447. /* contoken
  448. *  tokenize the strings which get passed to confile.
  449. *  Handles quotes and uses separators:  <33, ;:=
  450. */ 
  451. short contoken( char c)
  452. {
  453.     short        retval;
  454.     Boolean        success;
  455.  
  456.     if (c == EOF) {
  457.         Cspace[TelInfo->position++] = '\0';
  458.         sets_debug_print("Eof handler called");
  459.         confile(Cspace);
  460.         if (TelInfo->CONFactive) {
  461.                 success = CreateConnectionFromParams(SetParams);
  462.                 if (!success) {
  463.                     sets_debug_print("ERROR IN OPENING!! ");
  464.                     return(42);
  465.                     }
  466.                 }
  467.         return(-1);
  468.     }
  469.     
  470.     if (!TelInfo->position && !TelInfo->inquote && Sissep(c))
  471.     /*if (!TelInfo->position && Sissep(c))    */    /* old_skip over junk before keyword */
  472.         return(0);
  473.  
  474.     if (TelInfo->inquote || !Sissep(c)) {
  475.  
  476.         if (TelInfo->position > 200) {
  477.             sets_debug_print("Out of bounds error!");
  478.             return(1);
  479.         }
  480. /*
  481. *  check for quotes, a little mixed up here, could be reorganized
  482. */
  483.         if (c == '"' ) {
  484.             if (!TelInfo->inquote) {            /* beginning of quotes */
  485.                 TelInfo->inquote = 1;
  486.                 return(0);
  487.             }
  488.              Cspace[TelInfo->position++] =c;
  489.             return(0);
  490.         }
  491.         else 
  492.             {                        /* include in current string */
  493.             if (c != '\012' && c != '\015')        /* BYU 2.4.18 - changed \n to \015 and added \012 */
  494.                 {
  495.                 Cspace[TelInfo->position++] = c;
  496.                 return(0);
  497.                 }
  498.             }
  499.                 
  500.         }
  501.  
  502.     if (Cspace[TelInfo->position-1] == '"') TelInfo->position--;
  503.     Cspace[TelInfo->position++] = '\0';
  504.  
  505.     retval = confile(Cspace);            /* pass the token along */
  506.  
  507.     TelInfo->position = 0;
  508.     TelInfo->inquote = 0;
  509.     Cspace[0] = '\0';
  510.  
  511.     return(retval);
  512. }
  513.  
  514. /************************************************************************/
  515. /*  readconfig
  516. *   read the saved set file into our in-memory data structure.
  517. *   Handle everything by keyword (stored in resources).
  518. */
  519. void readconfig(FSSpec theSet)
  520. {
  521.     short c,retval;
  522.     short fn;
  523.     OSErr err;
  524.  
  525.     Cspace = NewPtr(256);                /* BYU LSC - get room for gathering stuff */
  526.  
  527.     SetParams = ReturnDefaultConnInitParams();
  528.     HLockHi((Handle)SetParams);
  529.     HLockHi((Handle)(**SetParams).session);
  530.     SetSessionPtr = *(**SetParams).session;
  531.     HLockHi((Handle)(**SetParams).terminal);
  532.     SetTerminalPtr = *(**SetParams).terminal;
  533.  
  534.     if (NULL == Cspace)                 /* no memory left for the set to load in */
  535.         {                                /* we're out of memory */
  536.         DoError(107 | MEMORY_ERRORCLASS, LEVEL2, NULL);    
  537.         return;
  538.         }
  539.     
  540.     TelInfo->position = TelInfo->CONFstate = TelInfo->CONFactive = TelInfo->inquote = TelInfo->lineno = 0;   /* state vars */    
  541.  
  542.     err = HOpen(theSet.vRefNum, theSet.parID, theSet.name, fsRdPerm, &fn);
  543.  
  544.     retval = 0;
  545.     while (!retval) {
  546.         c = Myfgetc(fn);
  547.         if (c == '#' && !TelInfo->inquote) {
  548.             while (c != EOF && c != '\012' && c != '\015')        /* skip to EOL */    /* BYU 2.4.18 - changed \n to \015 and added \012*/
  549.                 c = Myfgetc(fn);
  550.         }
  551.         if (c == '\012' || c == '\015')            /* BYU 2.4.18 - changed \n to \015 and added \012 */
  552.             TelInfo->lineno++;
  553.         retval = contoken(c);
  554.     }
  555.  
  556.     FSClose(fn);
  557.     DisposPtr((Ptr) Cspace);
  558.  
  559.     if (retval == EOF) {                /* EOF is normal end */
  560.         sets_debug_print("EOF termination");
  561.         }
  562.     else {
  563.         sets_debug_print("NON-EOF termination");
  564.         }
  565.         
  566.     return;
  567. }
  568.  
  569. void LoadSet( void)
  570. {
  571.     SFReply        sfr;
  572.     long        junk;
  573.     SFTypeList    typesok = {'CONF'};
  574.     Point        where;
  575.     FSSpec        set;
  576.  
  577.     where.h=100;where.v=100;
  578. #ifndef MPW
  579.     SFGetFile( where, "\pSet to load:", 0L, 1, typesok, 0L, &sfr);
  580. #else
  581.     SFGetFile( where, "Set to load:", 0L, 1, typesok,
  582.                     0L, &sfr);
  583. #endif MPW
  584.  
  585.     if (! sfr.good) return;
  586.  
  587.     BlockMove(&sfr.fName, set.name, (*sfr.fName)+1); // pstring copy sfr.fName -> set.name
  588.     GetWDInfo(sfr.vRefNum, &set.vRefNum, &set.parID, &junk);
  589.     readconfig(set);
  590. }
  591.  
  592. char Myfgetc(short myfile)
  593. {
  594.     OSErr err;
  595.     long count;
  596.     unsigned char buffer;
  597.     
  598.     count = 1;
  599.     if ((err = FSRead(myfile, &count, &buffer)) == eofErr)
  600.         buffer = EOF;
  601.     
  602.     return (buffer);
  603. }
  604.  
  605. void CStringToFile(short myfile, unsigned char *mystring) 
  606. {    
  607.     long mycount;                                        /* BYU LSC */
  608.     short fstatus;                                        /* BYU LSC */
  609.   
  610.   mycount = strlen((char *) mystring);                /* BYU LSC */
  611.   fstatus = FSWrite(myfile,&mycount,mystring);        /* BYU LSC */
  612. }
  613.  
  614.  
  615. void SaveSet( void)
  616. {
  617.     SFReply        sfr;
  618.     short        fn, truncate;
  619.     WindowPeek    wpeek;
  620.     Rect        rect;
  621.     Point        where;
  622.     long        junk;
  623.     char        temp[256], temp2[256];            /* BYU LSC */
  624.     unsigned short    red, green, blue;
  625.     short            fnum,fsiz;
  626.     short            i;
  627.     FSSpec        set;
  628.     OSErr        err;
  629.     Str255        scratchPstring;
  630.     
  631.     where.h = 100; where.v = 100;
  632. #ifndef MPW
  633.     SFPutFile( where, "\pSave Set to:", "\pTelnet Set", 0L, &sfr);    /* BYU LSC */
  634. #else
  635.     SFPutFile( where, "Save Set to:", "Telnet Set", 0L, &sfr);
  636. #endif
  637.  
  638.     if (! sfr.good)
  639.         return;
  640.  
  641.     BlockMove(&sfr.fName, set.name, (*sfr.fName)+1); // pstring copy sfr.fName -> set.name
  642.     GetWDInfo(sfr.vRefNum, &set.vRefNum, &set.parID, &junk);
  643.  
  644.     if (err = HCreate(set.vRefNum, set.parID, set.name, creator, filetype) == dupFNErr)
  645.         truncate = 1;
  646.         
  647.     err = HOpen(set.vRefNum, set.parID, set.name, fsWrPerm, &fn);
  648.  
  649.     if (truncate) 
  650.         SetEOF(fn, 0L);
  651.  
  652.     if (gApplicationPrefs->CommandKeys)
  653.         CStringToFile(fn,(unsigned char *) "commandkeys = yes\015");    /* BYU LSC */
  654.     else
  655.         CStringToFile(fn,(unsigned char *) "commandkeys = no\015");        /* BYU LSC */
  656.  
  657.     for (i = 0; i < 10; i++)
  658.       {
  659.         getmacro(i, (unsigned char *) temp);            /* BYU LSC */
  660.         if (*temp) {                                    /* BYU LSC */
  661.             sprintf(temp2, "key%d = \"", i);            /* BYU 2.4.16 */
  662.             strcat(temp2,temp);                            /* BYU LSC */
  663.             strcat(temp2,"\"\015");                        /* BYU LSC */
  664.             CStringToFile(fn,(unsigned char *) temp2);    /* BYU LSC */
  665.         }                                                /* BYU LSC */
  666.       } /* for */
  667.  
  668. #if 0                                                    /* BYU LSC */
  669.     for (i = 0; i < TelInfo->numwindows; i++)
  670.       {
  671.         short j;
  672.         j = RSgetfont(screens[i].vs, &fnum, &fsiz);
  673.       } /* for */
  674. #endif                                                    /* BYU LSC */
  675.  
  676.     for (i = 0; i < TelInfo->numwindows; i++)
  677.       {
  678.           GetWTitle(screens[i].wind, scratchPstring);
  679.           PtoCstr(scratchPstring);
  680.         sprintf(temp2, "name= \"%s\"\015", scratchPstring);
  681.         CStringToFile(fn,(unsigned char *) temp2);                /* BYU LSC */
  682.  
  683.         BlockMove((Ptr)screens[i].machine, (Ptr)scratchPstring, Length(screens[i].machine)+1);
  684.         PtoCstr(scratchPstring);
  685.         sprintf(temp2, "host= \"%s\"\015", scratchPstring);
  686.         CStringToFile(fn,(unsigned char *) temp2);                    /* BYU LSC */
  687.  
  688.         if (screens[i].ftpstate != 0)                            /* BYU 2.4.15 */
  689.             CStringToFile(fn,(unsigned char *)  "ftp= yes\015");    /* BYU mod */
  690.  
  691.         sprintf (temp2,"port= %d\015",screens[i].portNum);    /* NCSA: save port # */
  692.         CStringToFile(fn,(unsigned char *) temp2);                        /* BYU LSC */
  693.  
  694.         sprintf(temp2, "scrollback= %d\015", (screens[i].maxscroll));    /* BYU LSC */
  695.         CStringToFile(fn,(unsigned char *) temp2);                        /* BYU LSC */
  696.  
  697.         if (screens[i].bsdel)
  698.             CStringToFile(fn,(unsigned char *)  "erase = delete\015");        /* BYU LSC */
  699.         else
  700.             CStringToFile(fn,(unsigned char *)  "erase = backspace\015");    /* BYU LSC */
  701.  
  702.         wpeek = (WindowPeek) screens[i].wind;
  703.         rect = (*wpeek->contRgn)->rgnBBox;
  704.  
  705.         sprintf(temp2, "size = {%d,%d,%d,%d}\015", rect.top, rect.left,    /* BYU LSC */
  706.                     rect.bottom, rect.right);
  707.         CStringToFile(fn,(unsigned char *) temp2);                        /* BYU LSC */
  708.  
  709.         sprintf(temp2, "vtwidth = %d\015", screens[i].width);            /* BYU LSC */
  710.         CStringToFile(fn,(unsigned char *) temp2);                        /* BYU LSC */
  711.  
  712.         if (screens[i].tekclear)
  713.             CStringToFile(fn,(unsigned char *) "tekclear = yes\015");    /* BYU LSC */
  714.         else
  715.             CStringToFile(fn,(unsigned char *) "tekclear = no\015");    /* BYU LSC */
  716.  
  717.         if (theWorld.hasColorQD)
  718.           {
  719.             short j;
  720.             for (j = 0; j < 4; j++)
  721.               {
  722.                 RSgetcolor( screens[i].vs, j, &red, &green, &blue);
  723.                 sprintf(temp2, "rgb%d = {%u,%u,%u}\015",
  724.                     j, red, green, blue);
  725.                 CStringToFile(fn,(unsigned char *) temp2);
  726.               } /* for j */
  727.           } /* if */
  728.         RSgetfont( screens[i].vs, &fnum, &fsiz);
  729.         GetFontName( fnum, (StringPtr)temp);                                    /* BYU LSC */
  730. #ifndef MPW
  731.         p2cstr((unsigned char *) temp);                                /* BYU LSC */
  732. #endif
  733.  
  734.         sprintf( temp2, "font = \"%s\"\015", temp);                    /* BYU LSC */
  735.         CStringToFile(fn,(unsigned char *) temp2);                    /* BYU LSC */
  736.         sprintf( temp2, "fsize= %d\015", fsiz);                        /* BYU LSC */
  737.         CStringToFile(fn,(unsigned char *) temp2);                    /* BYU LSC */
  738.         
  739.         sprintf( temp2, "nlines= %d\015", VSgetlines(screens[i].vs));/* BYU LSC */
  740.         CStringToFile(fn,(unsigned char *) temp2);                    /* BYU LSC */
  741.         sprintf( temp2, "keystop= %d\015", screens[i].TELstop);        /* BYU LSC */
  742.         CStringToFile(fn,(unsigned char *) temp2);                    /* BYU LSC */
  743.         sprintf( temp2, "keygo= %d\015", screens[i].TELgo);            /* BYU LSC */
  744.         CStringToFile(fn,(unsigned char *) temp2);                    /* BYU LSC */
  745.         sprintf( temp2, "keyip= %d\015", screens[i].TELip);            /* BYU LSC */
  746.         CStringToFile(fn,(unsigned char *) temp2);                    /* BYU LSC */
  747.         sprintf( temp2, "crmap= %d\015", screens[i].crmap);        /* BYU LSC */
  748.         CStringToFile(fn,(unsigned char *) temp2);                    /* BYU LSC */
  749.         sprintf( temp2, "tekem= %d\015", screens[i].tektype);
  750.         CStringToFile(fn,(unsigned char *) temp2);
  751.         if (screens[i].national) {                        // Don't do this if using default translation table
  752.             GetItem(myMenus[National], screens[i].national+1, scratchPstring);
  753.             PtoCstr(scratchPstring);
  754.             sprintf(temp2, "translation= \"%s\"\015", scratchPstring);
  755.             CStringToFile(fn, (unsigned char *)temp2);
  756.             }
  757.         BlockMove(screens[i].answerback, scratchPstring, *(screens[i].answerback)+1);
  758.         PtoCstr(scratchPstring);
  759.         sprintf(temp2, "answerback= \"%s\"\015", scratchPstring);
  760.         CStringToFile(fn, (unsigned char *)temp2);
  761.       } /* for i */
  762.  
  763.     FSClose(fn);                        /* BYU LSC */
  764. }
  765.  
  766.